package TUILayer;
import java.util.Scanner;
import java.util.ArrayList;
import ControlLayer.DVDCtr;
import ModelLayer.*;
/**
 * User interface to the DVD controller
 * @author(kbh)
 * @version(2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2008.10.24: dvdmenu changed to If                   
 */

public class DvdUI
{
    private DVDCtr dvdCtr;//DVD UI must know the DVD controller 
    
    public DvdUI()
    {
        dvdCtr = new DVDCtr();
    }
    
    public void start()
    {
        dvdMenu();
    }
    
    public void dvdMenu()
   {
       boolean exit = false;
       while (!exit) {
           switch(writeDVDMenu()) {
               case 1: getDVD();
               pauseConsole();
               break;
               case 2: createDVD();
               pauseConsole();
               break;
               case 3: deleteDVD();
               pauseConsole();
               break;
               case 4: updateDVD();
               pauseConsole();
               break;
               case 5: createCopy();
               pauseConsole();
               break;
               
               default: // returns to mainMenu
               exit = true;
               break;
            }
        }
    }
    
    private int writeDVDMenu()
    {
           // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** DVD Menu ***");
            System.out.println(" (1) Find a DVD");
            System.out.println(" (2) Create a DVD");
            System.out.println(" (3) Delete DVD");
            System.out.println(" (4) Update DVD");
            System.out.println(" (5) Create DVD speciment");
            System.out.println(" (6) Return");
            System.out.print("\n Make your choice: ");
            
            int choice = keyboard.nextInt();
            return choice;
    }
    private int inputDVDId()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD number: ");
        int id = keyboard.nextInt();
        return id;
    }
        
    private String inputDVDTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }
    private String inputDVDDirector()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type movie director: " );
        String director = keyboard.nextLine();
        return director;
    }
    private int inputDVDReleaseDate()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type release date: ");
        int releaseDate = keyboard.nextInt();
        return releaseDate;
    }
    private int inputSerialNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type the copy number: ");
        int no = keyboard.nextInt();
        return no;
    }
    private int inputAccDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type acquisition date: ");
        int accDate = keyboard.nextInt();
        return accDate;
    }
    private int inputAccPrice()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type acquisition price: ");
        int accPrice = keyboard.nextInt();
        return accPrice;
    }
    
    //there is need for more methods to read information about DVDs
    //and methods to display the information
  
    private void getDVD()
    {     
        long id = inputDVDId();
        DVD dvd = dvdCtr.getDVD(id);
       if (dvd != null){
        System.out.print("Title: " + dvd.getTitle());
        System.out.println("Director: "+ dvd.getDirector() +"");
        System.out.println("Release Date: "+ dvd.getReleaseDate() +"");
    }
    else {
        System.out.println("This DVD identifier does not exist");
    }
        pauseConsole();
        
      
    }
    private void createDVD()
    {
        long id = inputDVDId();
        String title = inputDVDTitle();
        String director = inputDVDDirector();
        int releaseDate = inputDVDReleaseDate();
        
        dvdCtr.createDVD(id, title, director, releaseDate);
        
    }
    private void updateDVD()
    {
        long id = inputDVDId();
        String title = inputDVDTitle();
        String director = inputDVDDirector();
        int releaseDate = inputDVDReleaseDate();
        
        dvdCtr.updateDVD(id, title, director, releaseDate);
    }
    private void deleteDVD()
    {
        long id = inputDVDId();
        dvdCtr.deleteDVD(id);
    }
    
    private void createCopy()
    {
        long id = inputDVDId();
        DVD dvd = dvdCtr.getDVD(id);
        
        int serialNo = inputSerialNo();
        int accDate = inputAccDate();
        int accPrice = inputAccPrice();
        
        dvdCtr.createCopy(serialNo, accDate, accPrice, dvd);
    }
    
    private void listAllDvds()
    {
    }
    private void findCopies()
    {
        long id = inputDVDId();
        DVD dvd = dvdCtr.getDVD(id);
        
        ArrayList<Copy> dvdCopies = dvd.getCopies();
        
        for (Copy c : dvdCopies) {
            System.out.println("Serial number: " + c.getSerialNo());
        }
        
        pauseConsole();
         
    }
    
    private void pauseConsole()
    {
        System.out.println("Press the Any key to continue");
        Scanner sc = new Scanner(System.in);
        while(!sc.nextLine().equals(""));
    }
}